package com.JdkProxy.secondexample.utils;

import com.JdkProxy.secondexample.pojo.XiaoMingStudent;
import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @User c.c
 * @Since 2022/11/25
 * @Time 9:45
 * @Description 打印反射内容
 */

public class WriteProxyFile {
  byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy0", XiaoMingStudent.class.getInterfaces());
  //自定义写入文件位置
  String path = "D:/temp/Proxy.class";

  public void writeFile(){
    try {
      FileOutputStream outputStream = new FileOutputStream(path);
      outputStream.write(classFile);
      outputStream.flush();
      outputStream.close();
      System.out.println("代理文件写入成功");

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
